<?php
class User extends AppModel {
	public $name = 'User';
	
	/* public $hasMany = array(
        'Article' => array(
			'className' => 'Article',
			'foreignKey' => 'article_id'
        ),
		'Comment' => array(
            'className'     => 'Comment',
            'foreignKey'    => 'user_id'
        )
	);
	public $belongsTo = array(
		'Groups' => array(
			'className' => 'Groups',
			'foreignKey' => 'group_id'
		)
	); */
	
	function hashPass($pass){
		return md5($pass);
	}
	function doLogin($username=null,$pass=null) {
		$passHash = $this->hashPass($pass);
		debug($passHash);
		$user = $this->find('count', array(
			'conditions' => array(
				'User.user_name' => $username,
				'User.password' => $passHash
			)
		));
		if($user == 1){
			return true;
		}else{
			return false;
		}
	}
	function doRegister($user=null,$pass=null,$address=null,$group_name = null){
		$passHash = $this->hashPass($pass);
		
		//$data['User']['group_id'] = 1;
		$data['User']['user_name'] = $user;
		$data['User']['password'] = $passHash;
		//$data['User']['address'] = $address;
		
		$this->save($data);
	}
}